<template>
  <div searchResult-container>
    <van-nav-bar
      :title="`${$route.query.q}的搜索结果`"
      left-arrow
      @click-left="$router.back()"
      fixed
      placeholder
    />

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in list" :key="item.art_id" :title="item.title" />
    </van-list>
  </div>
</template>

<script>
import {getSearchList} from '@/views/home/home.js'
export default {
  name: 'searchResult',
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page:1
    }
  },
  methods: {
  async  onLoad () {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
     let res=await getSearchList({
       page:this.page,
       q:this.$route.query.q
     })
     console.log(res);
     this.list.push(...res.data.data.results)
this.page++
        // 加载状态结束
        this.loading = false

        // 数据全部加载完成
        if (res.data.data.results.length==0) {
          this.finished = true
        }
      
    }
  }
}
</script>

<style></style>
